package router

import (
	"github.com/gin-gonic/gin"
	"go_pure_admin_api/controllers"
	"go_pure_admin_api/middleware"
)

func UserRoutes() {
	RegisterRoute(func(rgPublic *gin.RouterGroup, rgAuth *gin.RouterGroup) {
		user := controllers.UserController{}
		rgPublicUser := rgPublic.Group("user").Use(func() gin.HandlerFunc {
			return func(ctx *gin.Context) {
				// 这里可以添加user公开的路由中间件
			}
		}())
		{
			rgPublicUser.POST("/login", user.Login)
			rgPublicUser.POST("/refresh-token", user.RefreshToken)
			rgPublicUser.Use(middleware.AuthToken()).GET("/getUserInfo", user.GetUserInfo)
			rgPublicUser.Use(middleware.AuthToken()).GET("/get-async-routes", user.GetAsyncRoutes)
			rgPublicUser.Use(middleware.AuthToken()).GET("/userAllList", user.GetAllUserList)
			rgPublicUser.Use(middleware.AuthToken()).POST("/uploadAvatar", user.UploadAvatar)
			rgPublicUser.Use(middleware.AuthToken()).GET("/getUserAvatar/:filename", user.GetUserAvatar)
			rgPublicUser.Use(middleware.AuthToken()).POST("/updateUserInfo", user.UpdateUserInfo)
			rgPublicUser.Use(middleware.AuthToken()).POST("/updateUserPassword", user.UpdateUserPassword)
		}
		rgAuthUser := rgAuth.Group("user")
		{

			rgAuthUser.POST("/userList", user.GetUserList)
			rgAuthUser.POST("/createUser", user.CreateUser)
			rgAuthUser.POST("/updateUser", user.UpdateUser)
			rgAuthUser.POST("/deleteUser", user.DeleteUser)
			rgAuthUser.GET("/listAllRole", user.GetAllRoleList)
			rgAuthUser.POST("/listRoleIds", user.GetUserRoleIds)
			rgAuthUser.POST("/updatePassword", user.UpdatePassword)
			rgAuthUser.POST("/updateUserRole", user.UpdateUserRole)
			rgAuthUser.POST("/batchDeleteUser", user.BatchDeleteUser)
		}
	})
}
